package com.baigt.juc.base.pool;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 类功能描述:
 * 线程池验证
 *      核心线程、最大线程、线程队列流转情况
 *
 * @author baigt
 * @version V1.0
 * @since 2019-10-23 10:56
 */
public class ThreadPoolDemo01 {
    static int maxSize=5;
    static ThreadPoolExecutor poolExecutor;
    static {
        poolExecutor = new ThreadPoolExecutor(2, maxSize, 3, TimeUnit.SECONDS,
            new LinkedBlockingQueue<>(3));
    }
    public static void main(String[] args) {
        for (int i = 0; i < maxSize; i++) {
            poolExecutor.submit(ThreadPoolDemo01::runDemo);
        }
        poolExecutor.shutdown();
    }

    public static void runDemo() {
        try {
            TimeUnit.SECONDS.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("queue size : "+poolExecutor.getQueue().size());
        System.out.println("active thread size: "+poolExecutor.getActiveCount());
    }
}
